import { RosterInterface } from '@/api/interface/personnel/roster/roster';
import { BasicForm } from '@/components/ProForm/interface/index';
import { PublicInterface } from '@/interface/public';

/**
 * 教育经历
 */

export function useEducationExperienceForm(proTableBox: PublicInterface.ProTableValue) {
  let educationExperienceForm = reactive<BasicForm<RosterInterface.ReqEducationInfoSave>>({
    form: {
      id: null,
      start: '',
      end: '',
      schoolName: '',
      major: '',
      flagGraduate: null,
      educationName: '',
      rosterId: null,
      remark: ''
    },
    title: '',
    minWidth: 660,
    labelWidth: [100, 120],
    visible: false,
    formAttrs: {
      labelWidth: '120px'
    },
    options: [
      {
        type: 'input',
        label: 'ID',
        prop: 'id',
        hide: true
      },
      {
        type: 'input',
        label: '主表id',
        prop: 'rosterId',
        hide: true
      },
      {
        type: 'date-picker',
        hide: false,
        prop: 'start',
        label: '开始日期',
        attrs: {
          type: 'date',
          valueFormat: BasicKey.DATE_FORMAT.YYYY_MM_DD
        },
        rules: [
          {
            required: true,
            message: '开始日期',
            trigger: 'change'
          }
        ]
      },
      {
        type: 'date-picker',
        hide: false,
        prop: 'end',
        label: '结束日期',
        attrs: {
          type: 'date',
          valueFormat: BasicKey.DATE_FORMAT.YYYY_MM_DD
        },
        rules: [
          {
            required: true,
            message: '结束日期',
            trigger: 'change'
          }
        ]
      },
      {
        type: 'input',
        hide: false,
        prop: 'schoolName',
        label: '学校名称',
        rules: [
          {
            required: true,
            message: '学校名称',
            trigger: 'blur'
          }
        ]
      },
      {
        type: 'input',
        hide: false,
        prop: 'major',
        label: '主修专业',
        rules: [
          {
            required: true,
            message: '主修专业',
            trigger: 'blur'
          }
        ]
      },
      {
        type: 'select',
        hide: false,
        prop: 'flagGraduate',
        label: '是否毕业',

        rules: [
          {
            required: true,
            message: '是否毕业',
            trigger: 'blur'
          }
        ],
        children: statusYesOrNo
      },

      {
        type: 'input',
        hide: false,
        prop: 'educationName',
        label: '取得学历',
        rules: [
          {
            required: true,
            message: '取得学历',
            trigger: 'blur'
          }
        ]
      },
      {
        type: 'input',
        hide: false,
        prop: 'remark',
        label: 'remark',
        attrs: {
          style: {
            width: '500px'
          }
        }
      }
    ]
  });

  /**
   * @description: 保存表单数据
   * @return {*}
   */
  const saveAddEducationExperienceForm = async form => {
    await educationInfoSave(form);
    educationExperienceForm.visible = false;
    elMessage();
    proTableBox.value?.getTableList();
  };

  return { educationExperienceForm, saveAddEducationExperienceForm };
}
